<template>
  <div>
    <el-dialog title="分配角色" :visible="isShowDialog" @close="btnCancel">
      <el-checkbox-group v-model="checkList">
        <el-checkbox
          v-for="role in roleList"
          :key="role.id"
          :label="role.id"
        >
          {{ role.name }}
        </el-checkbox>
      </el-checkbox-group>
      <template #footer>
        <el-row type="flex" justify="center">
          <el-button size="small" type="primary" @click="btnOK">确定</el-button>
          <el-button size="small" @click="btnCancel">取消</el-button>
        </el-row>
      </template>
    </el-dialog>
  </div>
</template>

<script>
// 获取员工详情

import { assignRoleAPI } from '@/api/employee'
import { getdetdilsapi } from '@/api/user'
// 引入获取角色列表函数
import { getRolelistAPI } from '@/api/setting'
export default {
  props: {
    isShowDialog: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      roleList: [],
      checkList: [],
      userId: ''
    }
  },
  created() {
    this.getRolelist()
  },
  methods: {
    async getRolelist() {
      const { rows } = await getRolelistAPI()
      this.roleList = rows
      console.log(34, this.roleList)
    },
    async getCheckList(id) {
      this.userId = id
      const { roleIds } = await getdetdilsapi(id)
      this.checkList = roleIds
      console.log(47, this.checkList)
    },
    async btnOK() {
      await assignRoleAPI({
        id: this.userId,
        roleIds: this.checkList
      })
      this.$message.success('修改成功')
      this.$emit('update:isShowDialog', false)
    },
    btnCancel() {
      this.checkList = []
      this.$emit('update:isShowDialog', false)
    }
  }
}

</script>

<style>

</style>
